package com.ohuang.test_compose.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Stable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color

private val DarkColorPalette = darkColors(
    primary = DarkPrimary,

    secondary = secondary
)
private val LightColorPalette = lightColors(
    primary = LightPrimary,

    secondary = secondary

    /* Other default colors to override
    background = Color.White,
    surface = Color.White,
    onPrimary = Color.White,
    onSecondary = Color.Black,
    onBackground = Color.Black,
    onSurface = Color.Black,
    */
)

private val LightAppColor = AppColors(
    statusBarColor = DarkPrimary,
    themeUi = secondary,
    background= Color.White,
    textPrimary= Color.Black,
    textSecondary= Color.Red,
    mainColor = DarkPrimary
)

private val DarkAppColor = AppColors(
    statusBarColor = DarkPrimary,
    themeUi = secondary,
    background= Color.Black,
    textPrimary= Color.White,
    textSecondary= Color.Red,
    mainColor = DarkPrimary
)

var LocalAppColors = compositionLocalOf {
    LightAppColor
}
//主题配置单例
@Stable
object CustomTheme {
    val colors: AppColors
        @Composable
        get() = LocalAppColors.current

    //创建主题枚举
    enum class Theme {
        Light, Dark
    }
}

@Composable
fun Custom_Theme( darkTheme: Boolean = isSystemInDarkTheme(),
                  content: @Composable() () -> Unit){
    val colors = if (darkTheme) {
        DarkAppColor
    } else {
        LightAppColor
    }
    CompositionLocalProvider(LocalAppColors provides colors) {
        content()
    }

}


@Composable
fun Test_composeTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable() () -> Unit
) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    MaterialTheme(
        colors = colors,
        typography = Typography,
        shapes = Shapes,
        content = content
    )
}